× Home Meet the Team Blog Make a Map

Make your own AI

Table of contents:

  1. The basics of a Peril AI
  2. Setting up your AI
  3. Importing your AI

1. The basics of a Peril AI

In peril the AIs all fundementally function the same way. Each round they observe the state of the game and act based on that information. They do not remmeber previous states of the game. This allows each AI to play for multiple players simultaneously.

There are three distinct actions every AI must perform:

  1. Reinforce
  2. Attack
  3. Fortify

The following optional operations can be performed at any point during those three actions:

  1. Buying blockades
  2. Upgrading units

AIs query the AIController to gather information about the game. Any information obtained from any other source is illegal.

2. Setting up your AI

Follow these steps to setting up your own AI class.

  1. Open the Peril.jar file in a achriver such as winrar.
  2. Extract peril/ai folder to your computer.
  3. Create a new <ai name>.java file inside peril.ai (The file name is you AI's name).
  4. The java class should look like this...
  5. 				
    package peril.ai;
    
    import peril.ai.api.*;
    
    public final class <ai name> extends AI{
    
    	public <ai name>(AIController api){
    		super("<ai name>", MAX_SPEED, api);
    	}
    
    	@Override
    	protected AIOperation processReinforce(AIController api) {
    		
    		final AIOperation operation = new AIOperation();
    		// Reinforce logic here
    		return operation;
    	}
    
    	@Override
    	protected AIOperation processAttack(AIController api) {
    
    		final AIOperation operation = new AIOperation();
    		// Attack logic here
    		return operation;
    	}
    
    	@Override
    	protected AIOperation processFortify(AIController api) {
    
    		final AIOperation operation = new AIOperation();
    		// Fortify logic here
    		return operation;
    	}
    }
    
    			
  6. Add the Logic for each operation. Details of each operation can be found here: Peril AI API. In specific the documentation for the methods your AI implements.

3. Importing your AI

Follow these steps to import your custom AI into Peril.

  1. Compile your <ai name>.java file to get the <ai name>.class
  2. Open the Peril.jar file in a achriver such as winrar.
  3. Copy the <ai name>.class back into the peril/ai inside the Peril.jar file.
  4. Close the Peril.jar file the open it again this time using Java. This should open Peril.
  5. Set up a new game and set the players you want to be your AI to control with with the AI as None.
  6. Load the game.
  7. At the earliest point possible, pause the game.
  8. Save the game into one of the save slots, remember which slot.
  9. Open the assets/maps/<map name>/ folder.
  10. Open the save .txt file.
  11. Near the top of the file there should be this...
    				
    ...
    Unit,Car,5,carIcon.png
    Unit,Tank,15,tankIcon.png
    Player,1,Hard,2,0,0,0,true,0
    Player,3,Medium,0,0,0,0,true,0
    Player,4,None,0,0,0,0,true,0
    Player,2,Easy,0,0,0,0,true,0
    State,Reinforce,1,0
    Country,Ural,000200150,Soldier:1,-20,20,2
    Country,India,050000050,Soldier:1,0,0,3
    ...
    
    			
  12. Replace the None with your <ai name> and save the file.
  13. Launch Peril.
  14. Load that modified game save and your AI should be in the game as the player(s) to set it to control.